package com.bruce.service.impl;

import com.bruce.Common.Result;
import com.bruce.Common.Resultcode;
import com.bruce.bean.*;
import com.bruce.bean.Dto.CourseplanDto;
import com.bruce.bean.Dto.SelectCourseDto;
import com.bruce.dao.CourseDao;
import com.bruce.dao.impl.CourseDaoImpl;
import com.bruce.service.CourseService;
import com.bruce.utils.PageUtils;

import java.util.List;

/**
 * @author cc
 * @date 2021/7/26 9:57
 * @Description
 */

public class CourseServiceImpl implements CourseService {
    CourseDao courseDao = new CourseDaoImpl();
    @Override
    public PageUtils<Course> FindALlCourse(PageUtils pageUtils) {
         pageUtils = courseDao.FindAllCourse(pageUtils);
       List temp = (List) pageUtils.getRecords();
        if (temp.size()<1){
            throw  new RuntimeException(Resultcode.Find_err.getMess());
        }
        return pageUtils;
    }

    @Override
    public Courseplan FindCourse(int cid) {
        return courseDao.FindCourse(cid);
    }

    @Override
    public Course findClassname(int cid) {
     return   courseDao.findCoursToname(cid);
    }

    @Override
    public PageUtils<CourseplanDto> FindCourseByStudentid(String sid, int pageindex) {

        return  courseDao.FindCourseByStudentid(sid,pageindex);
    }

    @Override
    public List<Sc> FindSidAndCidByStudentid(String sid) {
        return courseDao.FindSidAndCidByStudentid(sid);
    }

    @Override
    public Result InsertIntoCoursepla(Courseplan doAddcouForm) {

        int i = courseDao.InsertIntoCoursepla(doAddcouForm);
        if (i<1){
            throw new RuntimeException(Resultcode.Add_Error.getMess());
        }
        return Result.succ();
    }

    @Override
    public PageUtils<CourseplanDto> FindCourseByTeacheid(String tid, int parseInt) {

        return  courseDao.FindCourseByTeacheid(tid,parseInt);
    }

    @Override
    public Result UpdataCourse(Courseplan doAddcouForm) {
        int i  = 0;
        i = courseDao.UpdataCourse(doAddcouForm);
       if (i<1){
           throw  new RuntimeException(Resultcode.Update_err.getMess());
       }
        return Result.succ();
    }

    @Override
    public PageUtils<SelectCourseDto> FindSelecdCourse(String tid, String pageIndex) {
      return   courseDao.FindSelecdCourse(tid,pageIndex);
    }

    @Override
    public PageUtils<Student> FindStudentbyTeacheIdAndCourseId(String tid, String cid, String pageIndex) {
        return courseDao.FindStudentbyTeacheIdAndCourseId(tid,cid,pageIndex);
    }
}
